// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import { HOST } from 'service/HOST'
import { AlertPlugin, ToastPlugin } from 'vux'
import MintUi from 'mint-ui' // 移动样式组件库
import 'mint-ui/lib/style.css' // 移动样式组件库样式表
// import VueResoure from 'vue-resource' //vue ajax请求库
import Vuex from 'vuex' // vue 模块管理
import VueTouch from 'vue-touch'

import VueRouter from 'vue-router' // vue路由
import * as modules from 'modules' // 所有模块
import { router_config } from 'routers' //路由配置
import App from './App'

require('./js/tracking-min')
require('./js/face-min')

Vue.use(MintUi)
    // Vue.use(VueResoure)
Vue.use(AlertPlugin)
Vue.use(ToastPlugin)

Vue.use(Vuex)
Vue.use(VueRouter)
    // VueTouch.config.swipe = {
    //     threshold: 5
    // }
Vue.use(VueTouch, { name: 'v-touch' })



// console.log(modules)
// console.log(router_config)
/* eslint-disable no-new */
const store = new Vuex.Store({ // vuex状态管理
    state: { //根状态机
        HOST: HOST //资源服务器
    },
    modules: modules //状态机模块
})

const router = new VueRouter(router_config)

// //页面加载后添加各事件监听 cordova 必备

function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
    document.addEventListener("resume", onResume, false);
    document.addEventListener("pause", onPause, false);

}

//Cordova加载完毕
function onDeviceReady() {
    console.info('cordova', cordova)
    let permissions = cordova.plugins.permissions
    console.info('权限', permissions)
    let list = [
        permissions.CAMERA,
        //可以写多个权限
    ];
    permissions.requestPermissions(list, function(status) {
        new Vue({
            router,
            store,
            el: '#app',
            template: '<App/>',
            components: { App }
        })

    }, function() {
        alert('permission request fail')
    })


}

//进入后台
function onPause() {
    console.log("应用进入到后台！");
}

//恢复到前台
function onResume() {
    //alert("应用回到前台运行！");
}
window.onLoad = onLoad()


// 普通web
// new Vue({
//     router,
//     store,
//     el: '#app',
//     template: '<App/>',
//     components: { App }
// })